Skip to content

Add error handling for plan&execute agent #3845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 11, 2025

Conversation

Hailong-am
Copy link
Contributor

@Hailong-am Hailong-am commented May 13, 2025

Description

  1. Remove line separator from tool's response
  2. Index mapping tool support raw input for index parameter
  3. Add json extract logic for LLM output is not json format

Related Issues

#3848

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Hailong Cui <ihailong@amazon.com>
@pyek-bot
Copy link
Contributor

Thanks for the fixes @Hailong-am ! Let me know when it is ready for review. Can you also please create an issue for the fixes involved in this PR? Thanks!

Signed-off-by: Hailong Cui <ihailong@amazon.com>
@Hailong-am Hailong-am temporarily deployed to ml-commons-cicd-env-require-approval May 14, 2025 05:38 — with GitHub Actions Inactive
@Hailong-am Hailong-am temporarily deployed to ml-commons-cicd-env-require-approval May 14, 2025 05:38 — with GitHub Actions Inactive
@Hailong-am Hailong-am temporarily deployed to ml-commons-cicd-env-require-approval May 14, 2025 05:38 — with GitHub Actions Inactive
@Hailong-am Hailong-am temporarily deployed to ml-commons-cicd-env-require-approval May 14, 2025 05:38 — with GitHub Actions Inactive
@Hailong-am Hailong-am marked this pull request as ready for review May 14, 2025 05:53
@Hailong-am
Copy link
Contributor Author

Thanks for the fixes @Hailong-am ! Let me know when it is ready for review. Can you also please create an issue for the fixes involved in this PR? Thanks!

@pyek-bot PR description updated with issue number and the what's the actual fix, please help to take a look

Copy link

codecov bot commented May 14, 2025

Codecov Report

Attention: Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Project coverage is 80.28%. Comparing base (563120b) to head (608810a).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...thms/agent/MLPlanExecuteAndReflectAgentRunner.java 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3845      +/-   ##
============================================
+ Coverage     80.26%   80.28%   +0.02%     
- Complexity     7815     7820       +5     
============================================
  Files           683      683              
  Lines         34513    34519       +6     
  Branches       3839     3840       +1     
============================================
+ Hits          27702    27714      +12     
+ Misses         5107     5099       -8     
- Partials       1704     1706       +2     
Flag Coverage Δ
ml-commons 80.28% <87.50%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Hailong-am Hailong-am temporarily deployed to ml-commons-cicd-env-require-approval May 14, 2025 17:35 — with GitHub Actions Inactive
@Hailong-am Hailong-am temporarily deployed to ml-commons-cicd-env-require-approval May 14, 2025 17:35 — with GitHub Actions Inactive
Copy link
Contributor

@pyek-bot pyek-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes! Looks good!

@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env-require-approval June 3, 2025 19:55 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env-require-approval June 3, 2025 19:55 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env-require-approval June 3, 2025 19:55 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env-require-approval June 3, 2025 19:55 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env-require-approval June 5, 2025 23:54 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env-require-approval June 5, 2025 23:54 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env-require-approval June 5, 2025 23:54 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env-require-approval June 5, 2025 23:54 — with GitHub Actions Failure
@@ -528,6 +528,11 @@ String extractJsonFromMarkdown(String response) {
if (response.contains("```")) {
response = response.substring(0, response.lastIndexOf("```"));
}
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This method doesn't have any null check for response
  2. Is there any chance that multiple code block can exist?
  3. what about json array?
  4. what happens if there's any string literals like {"data": "{nested}"}
  5. Possible IndexOutOfBoundsException if markers aren't found
  6. why do we need second trim?
  7. Using substring multiple times creates multiple intermediate string objects
    Each operation like contains(), indexOf(), and lastIndexOf() scans through the string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method doesn't have any null check for response

response passed to this method could not be null, otherwise it will throw NPE before call it. But it's a good practice to add null check here

Is there any chance that multiple code block can exist?
what about json array?
what happens if there's any string literals like {"data": "{nested}"}

Yes, all of them are possible. the logic here is try our best to extract the expected json from LLM response.

Possible IndexOutOfBoundsException if markers aren't found

if markers are not found, it will not perform substring

why do we need second trim?

the content extracted from json block may have spaces, so trim is needed here before check it's a valid json string.

Using substring multiple times creates multiple intermediate string objects
Each operation like contains(), indexOf(), and lastIndexOf() scans through the string

that's not a big concern. the response is not large, and gc will help to handle intermediate string objects

Hailong-am and others added 2 commits June 9, 2025 17:33
Signed-off-by: Hailong Cui <ihailong@amazon.com>
ylwu-amzn
ylwu-amzn previously approved these changes Jun 10, 2025
@dhrubo-os
Copy link
Collaborator

@Hailong-am fix spotless please, ./gradlew spotlessApply

Signed-off-by: Hailong Cui <ihailong@amazon.com>
@Hailong-am Hailong-am temporarily deployed to ml-commons-cicd-env-require-approval June 11, 2025 00:43 — with GitHub Actions Inactive
@Hailong-am Hailong-am temporarily deployed to ml-commons-cicd-env-require-approval June 11, 2025 00:43 — with GitHub Actions Inactive
@Hailong-am Hailong-am temporarily deployed to ml-commons-cicd-env-require-approval June 11, 2025 00:43 — with GitHub Actions Inactive
@Hailong-am Hailong-am temporarily deployed to ml-commons-cicd-env-require-approval June 11, 2025 00:43 — with GitHub Actions Inactive
@Hailong-am
Copy link
Contributor Author

@Hailong-am fix spotless please, ./gradlew spotlessApply

@dhrubo-os @ylwu-amzn I have applied the spotless, can you review it again.

@Hailong-am Hailong-am had a problem deploying to ml-commons-cicd-env-require-approval June 11, 2025 01:49 — with GitHub Actions Failure
@Hailong-am Hailong-am had a problem deploying to ml-commons-cicd-env-require-approval June 11, 2025 01:49 — with GitHub Actions Failure
Signed-off-by: Hailong Cui <ihailong@amazon.com>
@Hailong-am Hailong-am had a problem deploying to ml-commons-cicd-env-require-approval June 11, 2025 02:38 — with GitHub Actions Error
@Hailong-am Hailong-am temporarily deployed to ml-commons-cicd-env-require-approval June 11, 2025 02:38 — with GitHub Actions Inactive
@Hailong-am Hailong-am had a problem deploying to ml-commons-cicd-env-require-approval June 11, 2025 02:38 — with GitHub Actions Failure
@Hailong-am Hailong-am temporarily deployed to ml-commons-cicd-env-require-approval June 11, 2025 02:38 — with GitHub Actions Inactive
@Hailong-am Hailong-am temporarily deployed to ml-commons-cicd-env-require-approval June 11, 2025 06:13 — with GitHub Actions Inactive
@Hailong-am Hailong-am temporarily deployed to ml-commons-cicd-env-require-approval June 11, 2025 06:13 — with GitHub Actions Inactive
@ylwu-amzn ylwu-amzn merged commit 50bcbda into opensearch-project:main Jun 11, 2025
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants